package org.vergil.core.thread.productionmessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.vergil.core.dao.test.TestRepository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by vergil on 17-4-8.
 */
@Component
public class Record implements Runnable {

    @Autowired
    private Business business;

    @Autowired
    private TestRepository testRepository;


//    Record(Business business){
//        this.business = business;
//    }

    @Override
    public void run() {
        while (true) {
            List<Map<String,Object>> list = new ArrayList<>();
            Map<String, Object> map = new HashMap<>();

            try {
                synchronized (this){
                    map = business.getRecord();
                    testRepository.save(map);
                }
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
